/*
 * 描述 @version 1 
 * Create by cy on 2018/9/26
 * */
const express=require('express');
const mongoose=require('mongoose');
const bodyParser=require('body-parser');
const passport = require('passport');
const app=express();

//DB config
const db=require('./config/key').mongoURL;
mongoose.connect(db,{useNewUrlParser:true})//这里可以直接写地址,这是变量;调用Mongoose的connect方法链接DB
    .then(()=>console.log('Mongodb connected'))
    .catch(err=>console.log(err));

// 使用body-parser中间件
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

//使用routers:/api/users---访问users:注册和登录的接口
//引入user.js
const users=require('./routers/api/users');
const profiles=require('./routers/api/profiles');
app.use('/api/users',users);
app.use('/api/profiles',profiles);

//passport初始化
app.use(passport.initialize());
require('./config/passport')(passport);//数据分离passport是指上面引入的对象

app.get('/',(req,res)=>{
    res.json({
        name:'cy'
    })
});

const port=process.env.PORT||5000;//就是个端口号

app.listen(port, () => {
    console.log(`server is running on ${port}`);//这里是` 在tab上面
});
